home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 515 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.magi.com!news!news.magi.com
  2. From: nredding@magi.com (Neil Redding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: char* string problem
  5. Date: Sat, 06 Jan 1996 10:48:18 -0500
  6. Organization: Magi Data Consulting
  7. Message-ID: <nredding-0601961048180001@magi03p09.magi.com>
  8. References: <4ci7gu$68r@cloner3.netcom.com> <820846052snz@intellic.demon.co.uk>
  9. NNTP-Posting-Host: magi03p09.magi.com
  10.  
  11. In article <820846052snz@intellic.demon.co.uk>,
  12. truemanc@intellic.demon.co.uk wrote:
  13.  
  14. >In article <4ci7gu$68r@cloner3.netcom.com>
  15. >           tstevens@ix.netcom.com "Edward Stevens " writes:
  16. >
  17. >>        I need to prepend some switch characters to some strings passed 
  18. >>to a main program which I have renamed for use as a function. 
  19. >>
  20. >>The calling program looks like this:
  21. >>
  22. >>char* the_args[4];
  23. >>char* Aprefix = " -A";
  24. >>char* Bprefix = " -B";
  25. >>char* CPrefix = " -C";
  26. >>char* Dprexix = " -D";
  27. >>
  28. >>the_args[0] = "user_name";
  29. >>the_args[0] = strcat(Aprefix,the_args[0]);
  30. >
  31. >Your problem is that the_args[0] is being set to the address of
  32. >Aprefix which points to three (3) blocks of memory. By executing the
  33. >strcat you are overwriting memory you have not already allocated.
  34. >
  35. >                        - Chris
  36. You are also attempting to modify a string constant , Aprefix, which is a no-no.
  37. If you want to modify Aprefix, you should declare it as an array, not a
  38. char pointer.
  39.  
  40. -- 
  41. Neil Redding
  42. Ottawa, Canada
  43.